package org.example;

/**
 * ThreadLocalUtils静态代码块中将threadLocal存入一个对象,是哪个线程操作的,
 * 就可以在哪个线程中取出.
 */
public class AppthreadLocalTest {
    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                Object object = ThreadLocalUtils.threadLocal.get();
                System.out.println(System.identityHashCode(object) + "---线程1---" + Thread.currentThread().getName());
            }
        }, "Thread-1").start();


        new Thread(new Runnable() {
            @Override
            public void run() {
                Object object = ThreadLocalUtils.threadLocal.get();
                System.out.println(System.identityHashCode(object) + "---线程2---" + Thread.currentThread().getName());
            }
        }, "Thread-2").start();

        Object object = ThreadLocalUtils.threadLocal.get();
        System.out.println( System.identityHashCode(object)+ "---主线程---" + Thread.currentThread().getName());
    }
}
